<?php
include('../db_connect.php');

$reset_ulink=true;

if($_POST["resetULinkID"] == ""){
	$reset_ulink=false;
    echo "Sorry, could not validate ULink ID.";
    return;
}

if(ereg('[^A-Za-z0-9]',$_POST['resetULinkID'])){
	$reset_ulink=false;
    echo "Sorry, could not validate ULink ID. Illegal characters were found.";
    return;
}
$str_length=strlen($_POST['resetULinkID']);
if($str_length<7 || $str_length >10){
    echo "Sorry, could not validate ULink ID.";
    return;
}

if($_POST["resetStudentID"] == "" || !is_numeric($_POST['resetStudentID'])){
	$reset_ulink=false;
    echo "Sorry, could not validate Student ID.";
    return;
}
$str_length=strlen($_POST['resetStudentID']);
if($str_length<6 || $str_length > 10){
    echo "Sorry, could not validate Student ID.";
    return;
}
if($_POST["facebookID"] == "" || !is_numeric($_POST['facebookID'])){
	$reset_ulink=false;
    echo "Sorry, could not validate Facebook ID.";
    return;
}

$ulink_id= htmlspecialchars(stripslashes(strip_tags( $_POST["resetULinkID"])));
$student_id=htmlspecialchars(stripslashes(strip_tags( $_POST["resetStudentID"])));
$facebookID=$_POST['facebookID'];


//make sure this facebook id does already exist
$sql="select user_id from fb_users where user_id='$facebookID'";
$result2= $db->Execute($sql);
if(!$result2->fields['user_id'])
{
    $reset_ulink=false;
    echo "Sorry, this Facebook ID does not exist.";
    return;
}
//we are validated, update ulink id/facebook id 
if($reset_ulink){
    $sql="update fb_users set student_id=$student_id, ulink_id='$ulink_id' where user_id=$facebookID";
    $db->Execute($sql);
    echo "Success! This Facebook user's ULink ID/Student ID has been reset.";

}

?>
